package com.bank.svc;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.bank.dao.BankOnlineDao;
import com.bank.dao.BankUserDao;
import com.bank.pojo.BankUserinfo;

@Service("bankOnlineSvc")
public class BankOnlineSvc {
	@Resource(name="bankUserDao")
	private BankUserDao bud;
	@Resource(name="bankOnlineDao")
	private BankOnlineDao bod;
	
	public int changeOnlineStatus(String phoneNum,String docNum,String cardNum,String flag){
		int isUserExist=bud.isUserExist(docNum, phoneNum);
		if(isUserExist==0){
			BankUserinfo user=bud.getUserByDoc(docNum);
			if(user.getUsersOnline()==0&&flag.equals("0")){
				return 3;//ALREADY OPENDED;
			}
			if(user.getUsersOnline()==1&&flag.equals("1")){
				return 4;//ALREADY CLOSED;
			}
			boolean result=bod.changeOnlineStatus(docNum, cardNum, flag);
			if(result){
				return 0;//SUCCEED
			}else{
				return 5;//ERROR
			}
		}
		return isUserExist;
	}
	
	public void setBud(BankUserDao bud) {
		this.bud = bud;
	}
	public void setBod(BankOnlineDao bod) {
		this.bod = bod;
	}
}
